package com.winbaoxian.testng.utils;

import com.winbaoxian.testng.enums.ActionType;
import com.winbaoxian.testng.model.core.action.ActionSettings;
import lombok.SneakyThrows;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum ConfigParseUtils {

    INSTANCE;

    private Logger log = LoggerFactory.getLogger(ConfigParseUtils.class);

    @SneakyThrows
    public Class<? extends ActionSettings> determineActionSettingsClass(ActionType type) {
        if (type == null) {
            return null;
        }
        String basePackage = ClassUtils.getPackageCanonicalName(ActionSettings.class);
        String className = String.format("%s.%sActionSettings", basePackage, StringUtils.capitalize(StringUtils.lowerCase(type.name())));
        Class clazz = ClassUtils.getClass(className);
        if (ClassUtils.isAssignable(clazz, ActionSettings.class)) {
            return clazz;
        }
        return null;
    }

}
